import logging

from django.core.management.base import BaseCommand

from application import settings
from plugins.dvadmin_tenant_backend.models import Client, Domain

logger = logging.getLogger(__name__)


class Command(BaseCommand):
    """
    项目初始化命令: python manage.py tenant_create
    """

    def handle(self, *args, **options):
        # create your first real tenant
        schema_name = input("请输入租户public (eg:public): ") or "public"
        name = input("请输入租户name (eg:public): ") or "public"
        domain_url = input("请输入租户domain (eg:public.kfm168.com): ") or 'public.kfm168.com'
        tenant, _ = Client.objects.get_or_create(schema_name=schema_name, name=name, paid_until='2021-12-31',
                                                 on_trial=True)
        domain = Domain()
        domain.domain = domain_url
        domain.tenant = tenant
        domain.is_primary = True
        domain.save()
